package cn.t222.ch04.aop;

import cn.t222.ch04.config.MyTest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class MyTestAspect {
    @Pointcut("@annotation(cn.t222.ch04.config.MyTest)")
    public void myPointcut() {}

    @Before("myPointcut()")
    public void before(JoinPoint joinPoint) {
        Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
        MyTest mytest = method.getAnnotation(MyTest.class);
        System.out.println(mytest.value());
    }
}
